#include"phonebook2.h"
#include<fstream>

int selectChoice() {
	std::cout << "1. Load from file" << std::endl;
	std::cout << "2. Add person" << std::endl;
	std::cout << "3. Remove person" << std::endl;
	std::cout << "4. By first" << std::endl;
	std::cout << "5. By last" << std::endl;
	std::cout << "6. Exit" << std::endl;
	int choice;
	std::cin >> choice;
	return choice;
}

void addPerson(PhoneBook & ph) {
	std::string first, last;
	std::cout << "First name: ";
	std::cin >> first;
	std::cout << std ::endl << "Last name: ";
	std::cin >> last;
	std::cout << std::endl;
	ph.add(first, last);
}

void removePerson(PhoneBook & ph) {
	std::string first, last;
	std::cout << "First name: ";
	std::cin >> first;
	std::cout << std ::endl << "Last name: ";
	std::cin >> last;
	std::cout << std::endl;
	ph.remove(first, last);
}

int main() {
	PhoneBook ph;
	int ch = selectChoice();
	std::ifstream in("./infile");
	while (ch != 6) {
		switch(ch) {
			case 1: in >> ph; break;
			case 2: addPerson(ph); break;
			case 3: removePerson(ph); break;
			case 4: ph.printByFirst(std::cout); break;
			case 5: ph.printByLast(std::cout); break;
		}
		ch = selectChoice();
	}
	return 0;
}